<template>
  <div class="box">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item :to="{ path: '/index/art-list' }">文档列表</el-breadcrumb-item>
          <el-breadcrumb-item>文档详情</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <div class="text item">
        <div class="content-header">
          <div class="title">{{article.title}}</div>
          <div class="desc">
            <div class="time">{{article.inputtime}}</div>
            <span>·</span>
            <div class="author">{{article.author}}</div>
          </div>
        </div>
        <div class="content-body" v-html="article.content"></div>
      </div>
    </el-card>
  </div>
</template>

<script>
import request from "@/api/article.js";
export default {
  data(){
    return{
      // 定义状态值存放文档对象
      article:{
        id:"",
        title:"",
        inputtime:"",
        author:"",
        content:"",
      },
    };
  },
  // 方法
  methods:{
    // 获取文档详情
    getDetail(){
      // 如何获取List页面传递过来的文档id呢？通过路由获取
      console.log(this.$route);
      let id = this.$route.query.id;
      request
        .getone(id)
        .then((r)=>{
          console.log(r);
          // 将服务器获取的对象赋值给状态值article
          this.article=r.data;
        })
        .catch((e)=>{
          console.log(e);
        });
    },
  },
  // 钩子函数
  created(){
    // 调用获取详情
    this.getDetail();
  },
  mounted(){},
};
</script>

<style scoped lang="scss">
.content-header{
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start;
  height: 100px;
  padding-bottom: 20px;
  margin-bottom: 30px;
  border: 2px solid blue;
  .title{
    line-height: 50px;
    height: 50px;
    font-size: 35px;
    font-weight: bold;
    color: blue;
  }
  .desc{
    font-size: 12px;
    font-weight: bold;
    color: #ccc;
    line-height: 30px;
    height: 30px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }
}
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 100%;
}
</style>